<template>
  <div>
    <div class="c-ph24">
      <MyClasslive-item :liveList="liveList"></MyClasslive-item>
      <loading-status-tem :dataStatus="dataStatus" noDataText="暂无直播"></loading-status-tem>
    </div>

    <div v-if="companyAuth != null && companyAuth.companyNav != null">
      <nav-bottom-bar :itemIndex="12" v-for="(item,index) in companyAuth.companyNav" :key="index" v-if="item.navType == 5"></nav-bottom-bar>
    </div>
  </div>
</template>
<script>
import MyClassliveItem from "@/components/templates/MyClassliveItem.vue";
import loadingStatusTem from "@/components/templates/common/loadingStatusTem.vue";
import NavBottomBar from "@/components/templates/common/navBottomBar.vue";
import { utilJs } from "@/utils/common.js";
const LIMIT = 20;
//let pageIndex = 0;
let page = 1;
export default {
  name: "MyClassList",
  components: {
    loadingStatusTem,
    MyClassliveItem,
    NavBottomBar,
  },
  props: [],
  data() {
    return {
      theme: localStorage.getItem("colorName")
        ? localStorage.getItem("colorName")
        : "mb5_default",
      dataStatus: 'HAS_MORE_DATA',
      liveList: [],
      companyAuth: localStorage.getItem("companyAuth") ? JSON.parse(localStorage.getItem("companyAuth")) : null,
      classId: this.$route.query.classId,
      last_page: 0
    };
  },
  created() {
    utilJs.appShare(this);
  },
  mounted() { },
  methods: {
    //通过小班课称模糊搜索专栏
    startSearch(e) {
      this.page = 1;
      this.liveList = [];
      this.searchText = e;
      this.getLiveList();
    },
    getLiveList() {
      if (this.dataStatus == 'LOADING') {
        return;
      }
      this.dataStatus = 'LOADING';
      utilJs.getMethod(`${global.apiurl}livePrivateClass/${this.classId}/myClassList?page=${page}&limit=${LIMIT}`,
        res => {
          this.companyAuth = JSON.parse(localStorage.getItem("companyAuth"));
          this.last_page = res.last_page
          if (page == 1) {
            this.liveList = res.data;
          } else {
            this.liveList = [...this.liveList, ...res.data];
          }
          if (res.data && (res.data.length < LIMIT)) {
            this.dataStatus = page == 1 && res.data.length == 0 ? 'NO_DATA' : 'NO_MORE_DATA';
          } else {
            this.dataStatus = 'HAS_MORE_DATA';
            //pageIndex += LIMIT;
            page++;
          }
        },
        failRes => {
          this.dataStatus = 'DATA_ERROR';
        }
      );
    },
    //分享
    wechatShare: function () {
      let shareUrl =
        window.location.href.split("#")[0] +
        "#" +
        this.$route.path +
        "?refereeId=" +
        localStorage.getItem("userId");
      utilJs.wechatConfig(shareUrl, "我的小班直播", "", "", function () { });
    },
    //手机端分享
    appShare: function () {
      let shareUrl =
        window.location.href.split("#")[0] +
        "#" +
        this.$route.path +
        "?refereeId=" +
        localStorage.getItem("userId");
      utilJs.appShareTrue("我的小班直播", "", shareUrl, "");
    },
    windowScrollFunction() {
      utilJs.handleLoading(() => {
        if (this.dataStatus == 'HAS_MORE_DATA' && this.liveList.length > 0) {
          this.getLiveList();
        }
      });
    },
    initData() {
      //pageIndex = 0;
      page = 1;
      this.dataStatus = 'HAS_MORE_DATA';
      this.liveList = [];
      this.getLiveList();
    },
  },
  activated() {
    setDocumentTitle("我的小班直播");// eslint-disable-line
    if (utilJs.checkNeedInitData(this.liveList, page)) {
      this.initData();
    }
    this.wechatShare();
    window.addEventListener('scroll', this.windowScrollFunction);
  },
  deactivated() {
    // this.dataStatus = 'NO_MORE_DATA';
    window.removeEventListener('scroll', this.windowScrollFunction);
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->

<style scoped>
</style>
